package cn.iocoder.yudao.module.cms.appversion.dal.mysql;

import cn.iocoder.yudao.framework.business.basic.dao.mapper.CoreMapper;
import cn.iocoder.yudao.framework.business.basic.dao.query.CoreLambdaQueryWrapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.cms.appversion.dal.dataobject.AppVersionDO;
import cn.iocoder.yudao.module.cms.appversion.vo.AppVersionPageReqVO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 版本更新 Mapper
 *
 * @author 山野羡民（1032694760@qq.com）
 */
@Mapper
public interface AppVersionMapper extends CoreMapper<AppVersionDO> {

    default PageResult<AppVersionDO> selectPage(AppVersionPageReqVO reqVO) {
        return selectPage(reqVO, new CoreLambdaQueryWrapper<AppVersionDO>()
                .eqIfPresent(AppVersionDO::getType, reqVO.getType())
                .eqIfPresent(AppVersionDO::getVersionCode, reqVO.getVersionCode())
                .eqIfPresent(AppVersionDO::getVersionName, reqVO.getVersionName())
                .betweenIfPresent(AppVersionDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(AppVersionDO::getType)
                .orderByDesc(AppVersionDO::getId));
    }

    default AppVersionDO selectLatestAppVersion(Integer type) {
        CoreLambdaQueryWrapper<AppVersionDO> wrapper = new CoreLambdaQueryWrapper<>();
        wrapper.eqIfPresent(AppVersionDO::getType, type);
        wrapper.limitN(1);
        wrapper.orderByDesc(AppVersionDO::getId);
        return selectOne(wrapper);
    }
}
